﻿#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <math.h>

typedef double Real;

typedef struct
{
	int n;
	char buf[255];
}Context;
Context context = { 0 };

void read_line(char* buf)
{
	char c;
	while (scanf("%c", &c))
	{
		if (c == '\n')
			break;
		*buf++ = c;
	}
	*buf = 0;
}

void swap(char* a, char* b)
{
	char c = *a;
	*a = *b;
	*b = c;
}

void reverse(char* s, char* e)
{
	while (s < e)
	{
		swap(s++, e--);
	}
}

void read_data(Context* ctx)
{
	read_line(ctx->buf);
	scanf("%d", &ctx->n);
}

void solve(Context* ctx)
{
	int sl = strlen(ctx->buf);
	int n = ctx->n % sl;
	reverse(ctx->buf, ctx->buf + n-1);
	reverse(ctx->buf+n, ctx->buf + sl-1);
	reverse(ctx->buf, ctx->buf + sl - 1);
	printf("%s\n", ctx->buf);
}

int main()
{
	freopen("D:/Develop/GitRepos/MOOC/浙江大学/数据结构/201906/DataStructure/M2019秋C入门和进阶练习集/7-177.txt", "r", stdin);
	read_data(&context);
	solve(&context);
	return 0;
}
